// components/pk-record/index.js
import {PkHandle} from "../../model/pk-handle"

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pk: Object
  },
  observers: {
    'pk': function (pk) {
      if (!pk) {
        return
      }
      const pkHandle = new PkHandle(pk)
      const leftDetail = pkHandle.getLeftDetail()
      const rightDetail = pkHandle.getRightDetail()
      const hasWinner = pkHandle.hasWinner()
      this.setData({
        leftDetail,
        rightDetail,
        hasWinner
      })
      if (hasWinner) {
        const winner = pkHandle.getWinner()
        this.setData({
          winner
        })
      }
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    leftDetail: null,
    rightDetail: null,
    hasWinner: false,
    winner: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onRecordTap() {
      wx.navigateTo({
        url: `/pages/pkDetail/pkDetail?pkid=${this.properties.pk.id}&source=normal`
      })
    }
  }
})
